package com.woniu.adopt_web.controller;

import com.github.pagehelper.PageInfo;

import com.woniu.adopt_web.entity.PetArticle;
import com.woniu.adopt_web.service.PetArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@Controller
@RequestMapping("petArticle")
public class PetArticleController {
    @Autowired
    PetArticleService petArticleService;

    @RequestMapping("/list")
    public String list(
            @RequestParam(value = "pageNum", defaultValue = "1", required = false) int pageNum,
            @RequestParam(value = "pageSize", defaultValue = "3", required = false) int pageSize,
            @RequestParam(value = "title", defaultValue = "", required = false) String title,
            Model model) {
        PageInfo<PetArticle> petArticlePageInfo = petArticleService.queryByPage(pageNum, pageSize, title);
        model.addAttribute("petArticlePageInfo", petArticlePageInfo);
        return "petArticle";
    }

    @RequestMapping("/detail")
    public String detail(@RequestParam(value = "id") int id, Model model) {
        PetArticle petArticle = petArticleService.queryById(id);
        model.addAttribute("petArticle", petArticle);
        return "petArticleDetail";
    }

}
